package com.chen.controller;

import com.chen.base.ResponseResult;
import com.chen.dto.RetreatDto;
import com.chen.dto.RetreatReqDto;
import com.chen.entity.Retreat;
import com.chen.service.RetreatService;
import com.chen.service.UserService;
import com.chen.vo.retreat.TasVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 退住
 * @author: ChenFY
 * @date: 2024/8/3
 */
@RestController
@RequestMapping("/elder")
public class RetreatController {

    @Resource
    private RetreatService retreatService;

    /**
     * 申请退住
     * @param retreatDto 传入退住对象
     * @return ResponseResult
     */
    @PostMapping("/create")
    public ResponseResult createRetreat(
            @RequestBody @ApiParam(value = "退住对象", required = true) Retreat retreatDto) {
        return retreatService.createRetreat(retreatDto);
    }

    /**
     * 退住表单查询
     * @param retreatCode 退住编码
     * @param assigneeId 处理人ID
     * @param flowStatus 流程状态
     * @param taskId 任务id
     * @return
     */
    @GetMapping
    public ResponseResult<TasVo> getRetreat(
            @RequestParam  String retreatCode,
            @RequestParam(required = false)  String assigneeId,
            @RequestParam  Integer flowStatus,
            @RequestParam(required = false) String taskId) {
        return retreatService.getRetreat(retreatCode, assigneeId, flowStatus, taskId);
    }

    /**
     * 提交
     * @param retreatDto 退住对象
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submitRetreat(@RequestBody  RetreatDto retreatDto) {
        return retreatService.submitRetreat(retreatDto);
    }

    /**
     *  驳回
     * @param retreatCode 退住编码
     * @param message 驳回消息
     * @param taskId 任务Id
     * @return
     */
    @PutMapping
    public ResponseResult disapprove(@RequestParam  String retreatCode, @RequestParam  String message, @RequestParam  String taskId) {
        return retreatService.disapprove(retreatCode, message, taskId);
    }

    /**
     *  审核拒绝
     * @param retreatCode 退住编码
     * @param reject 拒绝原因
     * @param taskId  任务Id
     * @return
     */
    @PutMapping("/reject")
    public ResponseResult auditReject(@RequestParam  String retreatCode, @RequestParam  String reject, @RequestParam  String taskId) {
        return retreatService.auditReject(retreatCode, reject, taskId);
    }

    /**
     *  撤回
     * @param retreatCode 退住编码
     * @param flowStatus 流程状态
     * @param taskId 任务Id
     * @return
     */
    @PutMapping("/revocation")
    public ResponseResult revocation(@RequestParam  String retreatCode, @RequestParam  Integer flowStatus, @RequestParam  String taskId) {
        return retreatService.revocation(retreatCode, flowStatus, taskId);
    }

    /**
     * 撤销
     * @param retreatCode 退住编码
     * @param taskId 任务Id
     * @return
     */
    @PutMapping("/cancel")
    public ResponseResult cancel(@RequestParam  String retreatCode, @RequestParam  String taskId){
        return retreatService.cancel(retreatCode, taskId);
    }

    /**
     * 分页查询
     * @param retreatReqDto
     * @return
     */
    @PostMapping("/selectByPage")
    public ResponseResult selectByPage(@RequestBody RetreatReqDto retreatReqDto) {
        return retreatService.selectByPage(retreatReqDto);
    }
}
